package src.helpers;

public class Semaphore {
    private int counter;
    private int sleepers;
    public Semaphore() {
    	counter=0;
    }
    
    public Semaphore(int counter){
    	this.counter=counter;
    }
    
    public synchronized void up(){
    	if(sleepers == 0){
    		counter++;
    	}else{
    		sleepers--;
    		notify();
    	}
    	
    }
    
    public synchronized void down() throws InterruptedException{
    	if(counter == 0){
    		sleepers++;
    		wait();
    	}else{
    		counter--;
    	}
    }
    
   	
}